import 'package:flutter/material.dart';
import 'dart:math';

class Example_02 extends StatefulWidget {
  const Example_02({super.key});

  @override
  State<Example_02> createState() => _Example_02State();
}

class _Example_02State extends State<Example_02> {

  int leftNumber = 1;
  int rightNumber = 1;
  void changeNumber() {
    setState(() {
      leftNumber = Random().nextInt(4) + 1;
      rightNumber = Random().nextInt(4) + 1;
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.red,
        appBar: AppBar(
          title: Text('摇骰子小游戏'),
          backgroundColor: Colors.red,
        ),
        body: Center(
            child: Row(
              children: [
                Expanded(
                    child: ElevatedButton(
                      onPressed: () {
                        changeNumber();
                      },
                      child: Image.asset('images/shaizi$leftNumber.png'),
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.red, // 设置背景色为绿色
                      ),
                    )
                ),
                Expanded(
                    child: ElevatedButton(
                      onPressed: () {
                        changeNumber();
                      },
                      child: Image.asset('images/shaizi$rightNumber.png'),
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.red, // 设置背景色为绿色
                      ),
                    )
                ),
              ],
            )
        )
    );
  }
}



